<template>
  <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login">
    <div class="layadmin-user-login-main">
      <div class="layadmin-user-login-box layadmin-user-login-header">
        <h2>PC管理系统</h2>
      </div>
      <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
          <input type="text" name="username" id="LAY-user-login-username"  placeholder="用户名" class="layui-input" v-model="name">
        </div>
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
          <input type="password" name="password" maxlength="" id="LAY-user-login-password"  placeholder="密码" class="layui-input" v-model="passw">
        </div>
        <div class="layui-form-item">
          <button class="layui-btn layui-btn-fluid kdlayuibtn" lay-submit lay-filter="LAY-user-login-submit" @click="goLogin">登 入</button>
        </div>
      </div>
    </div>
    <div class="layui-trans layadmin-user-login-footer">
      <p>© 2019 PC管理系统</p>
    </div>
  </div>
</template>
<script>
export default {
  name: 'login',
  data () {
    return {
      name:'',
      passw:'',
      curindex:1
    }
  },
  mounted(){
    localStorage.setItem("token","");
    
  },
  methods: {
    goLogin:function(){
      var _this = this;
      var name=this.name;
      var passw=this.passw;
      if(name==""){
        layer.msg("请输入正确用户名")
        return false;
      }
      if(passw==""){
        layer.msg("请输入正确登陆密码")
        return false;
      }
		  var data={
		    username:name,
		    password:passw
		  }
	 	  var url = '/mall/papi/v1.9/account';
		  ajaxRequest(url, 'POST', 'JSON', data, function(ret, err){
		  	//alert(JSON.stringify(ret)+"///登陆111")
		  	/*
		  	 rolesId 1管理员 2商家 3连锁商家  4 代理 5操作员 6店长
		  	 * */
        var type=ret.data.rolesId;
		  	if(type==2||type==1||type==3){
			  		localStorage.setItem("token",ret.data.token_type+" "+ret.data.access_token);
			    	localStorage.setItem("type",ret.data.rolesId);
		  		  localStorage.setItem("id",ret.data.userId);
		  		  localStorage.setItem("user",name);
			  	layer.msg(ret.message);
					setTimeout(function(){
            if(ret.data.shopId){
              localStorage.setItem("shopId",ret.data.shopId)
              localStorage.setItem("shopName",ret.data.shopName)
              localStorage.setItem("dealerId",ret.data.dealerId)
            }
            _this.$router.push({path:'/index'})
			  	},1000)
				}
		  	else{
  		  	layer.msg('请用商家账号或者管理员账号登录');
  		  }
		  })
    }

  },
  updated:function(){
		var _this = this;
		layui.use('form', function () {
    	var form = layui.form;
				form.render('select');
//				form.on('select(workerId)', function(data){
//				 	_this.workerId = data.value;
//				});
			});
  }
}
</script>
<style scoped>
	h2,.layadmin-user-login-footer p{color:#333;}
	.layadmin-user-login{background-color: #f2f2f2;font-size:14px;}
</style>
